﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using nl.tno.ict.multitouch.wpfmultitouch;

namespace TouchLibEvents
{
    public class FingerObject : BindableObject
    {
        public long Id { get; set; }

        private double _x;
        public double x { get { return _x; } set { _x = value; RaisePropertyChanged("x"); } }

        private double _y;
        public double y { get { return _y; } set { _y = value; RaisePropertyChanged("y"); } }

        public float m { get; set; }
        public float r { get; set; }

        private int tickCount;

        
        public List<Point> History { get; set; }

        public int TickCount { get { return tickCount; } set { tickCount = value; } }

        private DateTime time;

        /// <summary>
        /// How long this finger is on the table
        /// </summary>
        public TimeSpan TouchDuration { get { return new TimeSpan(DateTime.Now.Ticks - CreatedTime.Ticks); } }
        
        /// <summary>
        /// Moment finger was placed (for this finger with this ID)
        /// </summary>
        public DateTime CreatedTime { get; set; }

        /// <summary>
        /// Last update time for this finger
        /// </summary>
        public DateTime LastUpdateTime
        {
            get { return time; }
        }

        /// <summary>
        /// Last position before the current one
        /// </summary>
        public Point LastPosition { get; set; }                   

        /// <summary>
        /// Element that is being touched
        /// </summary>
        public Visual Element;

        public Point CurrentPosition
        {
            get
            {
                return new Point(x, y);
            }
            set
            {
                x = value.X;
                y = value.Y;
            }
        }

        public Point RelativePosition
        {
            get
            {
                return MTProcessing.GetInstance().MainWindow.TranslatePoint(CurrentPosition, (UIElement)((FrameworkElement)Element).Parent);                
            }
        }

        public override string ToString()
        {
            return (Id + ", " + x + ", " + y);
        }
        public FingerObject()
        {
            time = DateTime.Now;
            CreatedTime = DateTime.Now;
        }


    }
}
